package com.minis;

import java.util.*;

public class Main{

    public static void main(String[] argv){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] q = new int[n];
        for(int i=0;i<n;i++){
            q[i] = in.nextInt();
        }

        System.out.println(quickSelect(q,0,q.length-1,k));
        for(int i=0;i<n;i++){
            System.out.print(q[i]+" ");
        }
    }

    static int quickSelect(int[] q,int l,int r,int k){
        if(l >= r){
            return q[l];
        }
        int i=l-1,j=r+1,x=q[l+r>>1];
        while(i<j){
            do i++;while(q[i]<x);
            do j--;while(q[j]>x);
            if(i<j){
                int tmp = q[i];
                q[i] = q[j];
                q[j] = tmp;
            }
        }
        int len = j-i+1;
        if(len >= k){
            return quickSelect(q,l,j,k);
        }else{
            return quickSelect(q,j+1,r,k-len);
        }
    }
}